<?php require_once('../../core/import.php');?>
<?php User::Permission('USER_ADD'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <script type="text/javascript" src="../../scripts/import.js"></script>
    <script type="text/javascript" src="../../scripts/components/kindeditor/import.kindeditor.js"></script>
    <script type="text/javascript" src="scripts/add.js"></script>
</head>

<body>
    <form id="Form1" name="Form1" method="post" action="add.action.php" class="Form">
        <fieldset>
            <legend>管理员添加</legend>
            <table width="100%" cellpadding="1" cellspacing="0">
            <tr>
                <td width="130" height="25" align="left">
                	账号：
                </td>
                <td width="915" colspan="2">
                    <input type="text" id="Username" name="Username"  class="Textbox" />
                    <font color="red"> *</font>
                </td>
            </tr>
            <tr>
                <td width="130" height="25" align="left">
                	密码：
                </td>
                <td width="915" colspan="2">
                    <input type="password" id="Password" name="Password" class="Textbox" />
                    <font color="red"> *</font>
                </td>
            </tr>
            <tr>
                <td width="130" height="25" align="left">
                	重复输入密码：
                </td>
                <td width="915" colspan="2">
                    <input type="password" id="Password_Again" name="Password_Again" class="Textbox" />
                    <font color="red"> *</font>
                </td>
            </tr>
            <tr>
                <td width="130" height="25" align="left">
                	是否锁定：
                </td>
                <td width="915" colspan="2">
                  <input type="radio" name="M_locked" value="1" /> 是&nbsp;
	  			  <input type="radio" name="M_locked" value="0" checked/> 否 
                </td>
            </tr>
            <tr>
            	<td height="25" align="left" valign="top">角色：</td>
            	<td colspan="2">
                  <select id="ClassID" name="ClassID" class="text control_150" onchange="RoleID();">
                        <option value="null" selected="selected">-- 无角色 --</option>
				<?php
							$Role_Row=array();
							$Role_Row[0]['Permissions']='1,2';
							$Roles=Functions::UrlArgs('roleid');
							if($Roles){
								$Role_Row=DB::GetRows('select ID,Name,Permissions from management_user_role where ID='.$Roles.' order by ID asc');	
							}
							
                			foreach(DB::GetRows('select ID,Name,Permissions from management_user_role order by ID asc') as $Row)
                    		{
                        ?>                         
	                        <option value="<?php echo $Row['ID'];?>"  <?php if($Row['ID']==$Roles){?> selected="selected" <?php }?>><?php echo $Row['Name'];?></option>
                        <?php
                        	}
				?>
                    </select>
                  </td>
            </tr>
            </table>
        </fieldset>
	<table width="100%" cellpadding="1" cellspacing="0">
      	<?php
            $Modular=DB::GetRows('select Identifying,Name,Role,URL,Identifying_Parent from management_user_permission where Identifying_Parent is null or Branch=1 order by RealSort asc');
		?>
        <input type="hidden" value="<?php echo count($Modular) ?>" name="is_i"/>
        <?php
                  for($i=0;$i<count($Modular);$i++)
                  {
           			if(intval($i%2)==intval(0)){
					echo '<tr>';
					} 
		?>
            <td width="48%">
        	 <fieldset>
           	 <legend><?php echo $Modular[$i]['Name']; ?> 
           	 <input type="checkbox" name="Modular[]" value="<?php echo $Modular[$i]['Role']; ?>" <?php if(in_array($Modular[$i]['Role'],explode(',',$Role_Row[0]['Permissions']))){?> checked="checked" <?php } ?> onclick="MemberCheck(<?php echo $i;?>);"/></legend>
           	 <table width="100%" cellpadding="1" cellspacing="0">
             <tr>
             <?php
            $Function=DB::GetRows('select Identifying,Name,Role,URL,Identifying_Parent from management_user_permission where Identifying_Parent is not null and Identifying_Parent='.$Modular[$i]['Identifying'].' order by ID asc');
                  for($j=0;$j<count($Function);$j++)
                  {
		?>
                  <td>
                        <?php echo $Function[$j]['Name']?> <input type="checkbox" name="Function_<?php echo $i?>[]" value="<?php echo $Function[$j]['Role'] ?>" <?php if(in_array($Function[$j]['Role'],explode(',',$Role_Row[0]['Permissions']))){?> checked="checked" <?php } ?>/>
                  </td>
		<?php
           		if(intval(($j+1)%4)==intval(0)){
				echo '</tr>';
            	}
           }
            ?>
             </table>
             </fieldset>
           </td>
           <?php
           		if(intval($i%2)==intval(0)){
				echo '<td width="4%">&nbsp;</td>';
			}
           		if(intval($i%2)!=intval(0)){
				echo '</tr>';
            	}
           }
            ?>
	</table>
        <input id="ActionButton" name="ActionButton" type="submit" value="确定" class="button" /> <input id="ResetButton" name="ResetButton" type="reset" value="重置" class="button" />
    </form>
</body>
</html>